from pyglet.window import mouse
from container import StaticContainer
from wrapper import Label, Sprite
from widget import Widget
import view


class BasicButton(StaticContainer):

    def __init__(self, *args, **kwargs):
        StaticContainer.__init__(self, *args, **kwargs)
        self.register_fg(view.BeveledOutlay)

    def draw(self, rect=None):
        
        if self._clicked[mouse.LEFT] and\
           type(self._fg_view) is view.BeveledOutlay:
            
            self.unregister_fg()
            self.register_fg(view.BeveledBorder)

        elif not self._clicked[mouse.LEFT] and\
           type(self._fg_view) is view.BeveledBorder:

            self.unregister_fg()
            self.register_fg(view.BeveledOutlay)

        StaticContainer.draw(self, rect)


class TextButton(BasicButton):

    def __init__(self, text, text_args=(), text_kwargs={}, *args, **kwargs):
        BasicButton.__init__(self, *args, **kwargs)

        self._label = Label(text, *text_args, **text_kwargs)
        self.add_child(self._label)


class IllustratedButton(BasicButton):

    def __init__(self, img, *args, **kwargs):
        BasicButton.__init__(self, *args, **kwargs)
        
        self._img = Sprite(img)
        self.add_child(self._img)
